unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, UMono, UMonoIntf, UMonoRTTIInv, UScriptClass, UVarMono, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses Unit2;

{$R *.dfm}

procedure myShowMessage(aValue: PMonoString); cdecl;
var
  sw: string;
begin
  sw := TMonoConvert.MonoStrToString(aValue);
  Dialogs.ShowMessage('MONO: '+sw);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  vObj: variant;
  f: TForm2;
begin
  f := nil;
  if not OpenDialog1.Execute then
    exit;
  MonoJit := TMonoJit.Create('v4.0.30319', OpenDialog1.FileName, '0', 0);
  try
    MonoJit.AddInternalCall('Mono4Delphi','Dialogs','ShowMessage', @myShowMessage);
    MonoJit.AddInternalCall('Mono4Delphi','TProxyAnyIntf', 'DelphiInvoke', @DelphiRTTIInvoke);
    MonoJit.AddClassMap(TObject, 'Mono4Delphi.ITObject');
    MonoJit.AddClassMap(TComponent, 'Mono4Delphi.ITComponent');
    MonoJit.AddClassMap(TControl, 'Mono4Delphi.ITControl');
    MonoJit.AddClassMap(TForm, 'Mono4Delphi.ITForm');
    MonoJit.AddClassMap(TEdit, 'Mono4Delphi.ITEdit');
    MonoJit.AddClassMap(TButton, 'Mono4Delphi.ITButton');
    MonoJit.AddClassMap(TStrings, 'Mono4Delphi.ITStrings');
    MonoJit.AddClassMap(TMemo, 'Mono4Delphi.ITMemo');


    MonoJit.LoadAssembly;
    vObj := VarMonoCreate(MonoJit.FindMonoClass('Mono4Delphi', 'MainClass'));

    f := TForm2.Create(self);
    vObj.InitPlugin(O2V(f));
    f.ShowModal;

    vObj := NULL;
  finally
    f.Free;
    FreeAndNil(MonoJit);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  SetMonoPath('C:\Program Files\Mono-2.8.2\bin');
  InitMono;
end;

end.
